package api

import (
	"client/global"
	"context"
	"github.com/gin-gonic/gin"
	"server/proto"
	"strconv"
)

func AddFruit(c *gin.Context) {
	index := c.PostForm("index")
	name := c.PostForm("name")
	title := c.PostForm("title")
	content := c.PostForm("content")
	types := c.PostForm("type")
	i := c.PostForm("inventory")
	inventory, _ := strconv.Atoi(i)
	_, err := global.RpcClient.AddFruit(context.Background(), &proto.AddFruitReq{
		Name:      name,
		Title:     title,
		Content:   content,
		Index:     index,
		Type:      types,
		Inventory: int64(inventory),
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": -1,
			"msg":  err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
